package Utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
    /**
     * get the regex matcher group result by a String.
     * @param index the group index that default is 0.
     * @return {@code matcher.group[index]}.
     */
    public static String findSingleStr(String str,String regex,int... index){
        int num = index.length>0? index[0]:0;
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()){
            try{
                return matcher.group(num);
            }catch (IndexOutOfBoundsException e){
                e.printStackTrace();
            }
        }
        return "false";
    }
}
